//
//  PickNumBasketBallListViewController.m
//  PlayBall
//
//  Created by Sun Fanglei on 13-4-10.
//
//

#import "JddPickNumBasketBallListViewController.h"
#import "JddViewControllerManager.h"

@interface JddPickNumBasketBallListViewController ()

@end

@implementation JddPickNumBasketBallListViewController

@synthesize mutiLabel;
@synthesize titleLabel;
@synthesize passTypeLabel;
@synthesize countLabel;
@synthesize moneyLabel;
@synthesize bgScrollView;
@synthesize issue;
@synthesize numberArray;
@synthesize playMethodTemp;
@synthesize endTime;
@synthesize numberListTable;
@synthesize mutiTextField;
@synthesize buyButton;

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddPickNumBasketBallListViewController);

- (void)back {
    if (numberArray.count >0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"退出提示"
                                                        message:@"退出后您的投注将不会保存，确认继续?"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:@"取消", nil];
        [alert show];

    }else{
        JddPickNumBasketBallViewController *p = (JddPickNumBasketBallViewController *)self.fromController;
        [p clearBtn:nil];
        [[JddViewControllerManager sharedInstance] popToBackViewController];
    }
}

- (void)setBackBtnAction {
	UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
	temporaryBarButtonItem.target = self;
	temporaryBarButtonItem.title = @"竞彩篮球";
	temporaryBarButtonItem.action = @selector(back);
	self.navigationItem.leftBarButtonItem = temporaryBarButtonItem;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
	NSCharacterSet *cs;
	cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789\n"]invertedSet];
    
	NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
    
	BOOL canChange = [string isEqualToString:filtered];
    
	if (!canChange) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:@"倍数只能输入数字"
		                                               delegate:nil
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:nil, nil];
		[alert show];
		return NO;
	}
	if ([string length] + range.location > 5) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:@"倍数不能大于99999"
		                                               delegate:nil
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:nil, nil];
		[alert show];
		return NO;
	}
    
	if ([textField.text length] == 0) {
		if ([string isEqualToString:@"0"]) {
			return NO;
		}
		else {
			moneyLabel.text = [NSString stringWithFormat:@"%0.0f彩豆", count * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
			return YES;
		}
	}
	if (range.location >= 5) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:@"倍数不能大于99999"
		                                               delegate:nil
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:nil, nil];
		[alert show];
		return NO;
	}
	else {
		moneyLabel.text = [NSString stringWithFormat:@"%0.0f彩豆", count * [[textField.text stringByReplacingCharactersInRange:range withString:string] intValue] * 2];
		return YES;
	}
}

- (BOOL)textFieldShouldClear:(UITextField *)textField {
	return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
	UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];
	tapGestureRecognizer.delegate = self;
	[self.bgScrollView addGestureRecognizer:tapGestureRecognizer];
    
	[self.bgScrollView setContentOffset:CGPointMake(0, 213) animated:YES];
	return YES;
}

- (IBAction)handleSingleTapGesture:(UITapGestureRecognizer *)sender {
	if ([mutiTextField.text length] == 0) {
		mutiTextField.text = @"1";
	}
	[mutiTextField resignFirstResponder];
	mutiLabel.text = [NSString stringWithFormat:@"%@倍", mutiTextField.text];
	moneyLabel.text = [NSString stringWithFormat:@"%3.0f彩豆", count * [mutiTextField.text floatValue] * 2];
	[self.bgScrollView removeGestureRecognizer:sender];
	[self.bgScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
	return DELETE;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [numberArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
		JddSportListItemHHCell *cell = [self getHHCellWithIndexPath:indexPath];
		return 40 + cell.contentLbl.frame.size.height;
	}
    else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
        JddSportListItemZJQCell *cell = [self getSFCCellWithIndexPath:indexPath];
        return 40 + cell.numbersLbl.frame.size.height;
    }
	else {
		return 65.0;
	}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	//让分胜负，胜负，大小分 
	if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_RFSF
        || self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SF
        || self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_DXF) {
		JddBasketBallListItemCell *cell = [JddBasketBallListItemCell getInstanceView];
		JddSportNumber *bbNumber = [numberArray objectAtIndex:indexPath.row];
		cell.fistTeamName.text = bbNumber.Vteam;
		cell.secondTeamName.text = bbNumber.Hteam;
		for (int b = 0; b < [bbNumber.teamArray count]; ++b) {
			NSString *sptemp = [bbNumber.teamArray objectAtIndex:b];
			switch ([sptemp intValue]) {
				case 1:
                    if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_DXF) {
                        cell.firstTeamBtn.selected = YES;
                        [cell.firstTeamBtn setTitle:@"大分" forState:UIControlStateNormal];
                    }else{
                        cell.secondTeamBtn.selected = YES;
                        }
					break;
				case 2:
					if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_DXF) {
                        cell.secondTeamBtn.selected = YES;
                        [cell.secondTeamBtn setTitle:@"小分" forState:UIControlStateNormal];
                    }else{
						cell.firstTeamBtn.selected = YES;
                    }
					break;
                    
				default:
					break;
			}
		}
		cell.tag = indexPath.row;
		cell.delegate = self;
		return cell;
	}
    //胜分差
    else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
        JddSportListItemZJQCell *cell = [self getSFCCellWithIndexPath:indexPath];
        return cell;
	}
	//混合
	else{
		JddSportListItemHHCell *cell = [self getHHCellWithIndexPath:indexPath];
		return cell;
	}
}

-(JddSportListItemZJQCell *)getSFCCellWithIndexPath:(NSIndexPath *)indexPath {
    JddSportListItemZJQCell *cell = [JddSportListItemZJQCell getInstanceView];
    JddSportNumber *ssqNumber = [numberArray objectAtIndex:indexPath.row];
    cell.HTeam.text = ssqNumber.Vteam;
    cell.VTeam.text = ssqNumber.Hteam;
    NSMutableArray *numbersArr = [NSMutableArray arrayWithArray:[JddCommonFunction sortArray:ssqNumber.teamArray]];
    NSString *numbersStr = [numbersArr componentsJoinedByString:@","];
    cell.numbersLbl.text = numbersStr;
    cell.tag = indexPath.row;
    cell.delegate = self;
    [self setHeightWithLable:cell.numbersLbl];
    return cell;
}

- (JddSportListItemHHCell *)getHHCellWithIndexPath:(NSIndexPath *)indexPath {
	JddSportListItemHHCell *cell = [JddSportListItemHHCell getInstanceView];
	JddSportNumber *ssqNumber = [numberArray objectAtIndex:indexPath.row];
	cell.teamLbl.text = [NSString stringWithFormat:@"%@ VS %@",  ssqNumber.Hteam,ssqNumber.Vteam];
	NSArray *codeArr = [ssqNumber.code componentsSeparatedByString:@"/"];
	cell.wkLbl.text = [codeArr objectAtIndex:0];
    
	NSString *fontA = @"<font color='#1E90FF'>";
	NSString *fontB = @"</font>";
	NSMutableString *resultStr = [NSMutableString string];
    
	NSMutableArray *resultArr = ssqNumber.teamArray;
	NSMutableArray *spfArr = [resultArr objectAtIndex:0];
	NSMutableArray *rqspfArr = [resultArr objectAtIndex:1];
	NSMutableArray *zjcArr = [resultArr objectAtIndex:2];
	NSMutableArray *bqcArr = [resultArr objectAtIndex:3];
	NSMutableArray *bfArr = [resultArr objectAtIndex:4];
    
	if (spfArr.count > 1) {
		NSString *spfStr = [spfArr componentsJoinedByString:@""];
		NSArray *spfA = [spfStr componentsSeparatedByString:@":"];
		NSString *spfTitle = [spfA objectAtIndex:0];
		NSString *spfContent = [spfA objectAtIndex:1];
		[resultStr appendString:[NSString stringWithFormat:@"%@%@:%@%@\n", fontA, spfTitle, fontB, spfContent]];
	}
	if (rqspfArr.count > 1) {
		NSString *rqspfStr = [rqspfArr componentsJoinedByString:@""];
		NSArray *rqspfA = [rqspfStr componentsSeparatedByString:@":"];
		NSString *rqspfTitle = [rqspfA objectAtIndex:0];
		NSString *rqspfContent = [rqspfA objectAtIndex:1];
		[resultStr appendString:[NSString stringWithFormat:@"%@%@:%@%@\n", fontA, rqspfTitle, fontB, rqspfContent]];
	}
	if (zjcArr.count > 1) {
		NSString *zjcStr = [zjcArr componentsJoinedByString:@""];
		NSArray *zjcA = [zjcStr componentsSeparatedByString:@":"];
		NSString *zjcTitle = [zjcA objectAtIndex:0];
		NSString *zjcContent = [zjcA objectAtIndex:1];
		[resultStr appendString:[NSString stringWithFormat:@"%@%@:%@%@\n", fontA, zjcTitle, fontB, zjcContent]];
	}
	if (bqcArr.count > 0 || bfArr.count > 0) {
		NSMutableString *sfcStr = [NSMutableString stringWithString:@"胜分差:"];
		if (bqcArr.count > 0) {
			NSString *bqcStr = [bqcArr componentsJoinedByString:@""];
			[sfcStr appendString:bqcStr];
		}
		if (bfArr.count > 0) {
			NSString *bfStr = [bfArr componentsJoinedByString:@""];
			[sfcStr appendString:bfStr];
		}
		NSArray *bfA = [sfcStr componentsSeparatedByString:@":"];
		NSString *bfTitle = [bfA objectAtIndex:0];
		NSString *bfContent = [bfA objectAtIndex:1];
		[resultStr appendString:[NSString stringWithFormat:@"%@%@:%@%@", fontA, bfTitle, fontB, bfContent]];
	}
    
	cell.contentLbl.attributedText = [JddCommonFunction convertHTMLFontRedWithResult:resultStr AndCellLabel:cell.contentLbl];
	[self setHeightWithLable:cell.contentLbl];
    
	cell.tag = indexPath.row;
	cell.delegate = self;
	return cell;
}

- (void)setHeightWithLable:(UILabel *)lbl {
	lbl.numberOfLines = 0;
	CGRect frame = lbl.frame;
	UIFont *font = lbl.font;
	CGFloat width = frame.size.width;
	NSString *result = lbl.text;
	lbl.lineBreakMode = NSLineBreakByWordWrapping;
	//替换html使不影响计算高度
	result = [result stringByReplacingOccurrencesOfString:@"<font color='#1E90FF'>" withString:@""];
	result = [result stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    
	CGSize size = [result sizeWithFont:font constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
	frame.size.height = size.height;
	[lbl setFrame:frame];
}

- (void)deleteRowAtrowNumber:(NSNumber *)rowNumber {
	for (int i = [rowNumber intValue] + 1; i < [numberArray count]; ++i) {
		NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
		UITableViewCell *cell = [numberListTable cellForRowAtIndexPath:indexPath];
		cell.tag--;
	}
	[numberArray removeObjectAtIndex:[rowNumber intValue]];
	[numberListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[rowNumber intValue] inSection:0]] withRowAnimation:YES];
	NSString *etStr = @"";
	if ([numberArray count] > 1) {
		JddSportNumber *sportnum1 = [numberArray objectAtIndex:0];
		NSDate *date1 = [JddCommonFunction dateFromString:sportnum1.endTime];
		for (JddSportNumber *sportnum in numberArray) {
			NSDate *date2 = [JddCommonFunction dateFromString:sportnum.endTime];
			date1 =  [date2 earlierDate:date1];
		}
		endTime = date1;
		NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
		[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
		etStr = [dateFormatter stringFromDate:endTime];
	}
	else if ([numberArray count] == 1) {
		JddSportNumber *sportnum1 = [numberArray objectAtIndex:0];
		NSDate *date1 = [JddCommonFunction dateFromString:sportnum1.endTime];
		endTime = date1;
		NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
		[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
		etStr = [dateFormatter stringFromDate:endTime];
	}
	else {
		etStr = @"--------------";
	}
	self.titleLabel.text = [NSString stringWithFormat:@"共选择%d场,截止时间:%@", [numberArray count], etStr];
	playMethodTemp = [[NSMutableArray alloc]init];
	passTypeLabel.text = @"";
	[self caculateMoneyAndCount];
}

- (void)SportListItemCellDeleteButtonClicked:(NSNumber *)rowNumber {
	[self deleteRowAtrowNumber:rowNumber];
}

- (void)BasketBallListItemCellDeleteButtonClicked:(NSNumber *)rowNumber {
	[self deleteRowAtrowNumber:rowNumber];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
	if ([touch.view isDescendantOfView:buyButton]) {
		return NO;
	}
	return YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	if ([[alertView message] isEqualToString:@"您还没有登录，请先登录"]) {
		if (buttonIndex == 0) {
			[[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN
			                                                        fromController:self
			                                                            withObject:nil
			                                                           withObject2:nil];
		}
	}
	else if ([[alertView message] isEqualToString:@"确认购买？"]) {
		if (buttonIndex == 0) {
			[self sureToBuy];
		}
	}
	else if ([[alertView message] isEqualToString:@"确认清空列表？"]) {
		if (buttonIndex == 0) {
			playMethodTemp = [[NSMutableArray alloc] init];
			numberArray = [[NSMutableArray alloc] init];
			mutiTextField.text = @"1";
			passTypeLabel.text = @"";
			count = 0;
			self.titleLabel.text = @"共选择0场,截止时间:--------------";
			countLabel.text = [NSString stringWithFormat:@"%3.0f注", count];
			mutiLabel.text = [NSString stringWithFormat:@"%@倍", mutiTextField.text];
			moneyLabel.text = [NSString stringWithFormat:@"%3.0f彩豆", count * [mutiTextField.text floatValue] * 2];
			[numberListTable reloadData];
		}
	}
	else if ([[alertView title] isEqualToString:@"退出提示"]) {
		if (buttonIndex == 0) {
			JddPickNumBasketBallViewController *p = (JddPickNumBasketBallViewController *)self.fromController;
			[p clearBtn:nil];
			[[JddViewControllerManager sharedInstance] popToBackViewController];
		}
	}
}

- (void)sureToBuy {
	if ([self checkValue]) {
		[JddCommonFunction setWaitingViewHidden:NO fromController:self];
		JddBuyLotteryOperation *operation2 = [[JddBuyLotteryOperation alloc] init];
		operation2.delegate = self;
		operation2.lotteryTypeId = [NSNumber numberWithInt:LOTTERY_TYPE_ID_BASKETBALL];
		operation2.issueId = [NSNumber numberWithInt:2013];
		operation2.multiple = [NSNumber numberWithInt:[mutiTextField.text intValue]];
		operation2.moneyAmount = [NSNumber numberWithFloat:count * [mutiTextField.text floatValue] * 2];
		operation2.lotteryNumber = [self lotteryNumberList];
		[[JddGlobalParameter sharedInstance].operationQueue addOperation:operation2];
	}
}

- (NSMutableArray *)lotteryNumberList {
	NSMutableArray *paramNumberArray = [[NSMutableArray alloc] init];
	NSMutableString *lotteryNumberString = [NSMutableString string];
	NSMutableDictionary *numDic = [[NSMutableDictionary alloc] init];
	[numDic setObject:[NSNumber numberWithInt:self.playId] forKey:@"playid"];
    
	for (int i = 0; i < [numberArray count]; ++i) {
		JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
		if (i != 0) {
			[lotteryNumberString appendString:@","];
		}
		//131101001=
		NSString *code = ssqNumber.code;
        NSString *team1 = [ssqNumber.teamArray componentsJoinedByString:@"/"];
		NSMutableString *teamhh = [NSMutableString string];
		//混合
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
			NSArray *codeArr = [ssqNumber.code componentsSeparatedByString:@"/"];
			code = [codeArr objectAtIndex:1];
		}
		[lotteryNumberString appendString:code];
		[lotteryNumberString appendString:@"="];
		//胜分差
        if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜1-5"withString:@"11"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜6-10"withString:@"12"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜11-15"withString:@"13"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜16-20"withString:@"14"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜21-25"withString:@"15"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"客胜26+"withString:@"16"];

            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜1-5"withString:@"01"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜6-10"withString:@"02"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜11-15"withString:@"03"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜16-20"withString:@"04"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜21-25"withString:@"05"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@"主胜26+"withString:@"06"];
            team1 = [team1 stringByReplacingOccurrencesOfString:@" "withString:@""];
        }
        
		//混合
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
			BOOL bf = YES;
			NSMutableArray *resultArr = ssqNumber.teamArray;
			NSMutableArray *sfArr = [resultArr objectAtIndex:0];
			NSMutableArray *rfsfArr = [resultArr objectAtIndex:1];
			NSMutableArray *dxfArr = [resultArr objectAtIndex:2];
			NSMutableArray *ksArr = [resultArr objectAtIndex:3];
			NSMutableArray *zsArr = [resultArr objectAtIndex:4];
			//让分胜负
			if (rfsfArr.count > 1) {
				bf = NO;
				NSMutableArray *rqspfA = [NSMutableArray array];
				for (int i = 1; i < rfsfArr.count; i++) {
					[rqspfA addObject:[rfsfArr objectAtIndex:i]];
				}
				NSString *rqspfContent = [rqspfA componentsJoinedByString:@"/"];
				rqspfContent = [rqspfContent stringByReplacingOccurrencesOfString:@"主胜"withString:@"1"];
				rqspfContent = [rqspfContent stringByReplacingOccurrencesOfString:@"主负"withString:@"2"];
				rqspfContent = [rqspfContent stringByReplacingOccurrencesOfString:@" "withString:@""];
				[teamhh appendString:[NSString stringWithFormat:@"%@%@", @"1_", rqspfContent]];
			}
			//胜负
			if (sfArr.count > 1) {
				NSString *tag = @"^2_";
				if (bf) {
					tag = @"2_";
					bf = NO;
				}
				NSMutableArray *spfA = [NSMutableArray array];
				for (int i = 1; i < sfArr.count; i++) {
					[spfA addObject:[sfArr objectAtIndex:i]];
				}
				NSString *spfContent = [spfA componentsJoinedByString:@"/"];
				spfContent = [spfContent stringByReplacingOccurrencesOfString:@"主胜"withString:@"1"];
				spfContent = [spfContent stringByReplacingOccurrencesOfString:@"主负"withString:@"2"];
				spfContent = [spfContent stringByReplacingOccurrencesOfString:@" "withString:@""];
				[teamhh appendString:[NSString stringWithFormat:@"%@%@", tag, spfContent]];
			}
			//胜分差
			if (zsArr.count > 0 || ksArr.count > 0) {
				NSMutableString *content = [NSMutableString string];
				BOOL zsExist = NO;
				if (zsArr.count > 0) {
					zsExist = YES;
					NSString *sfcContent = [zsArr componentsJoinedByString:@"/"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"客胜("withString:@""];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"主胜("withString:@""];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@")"withString:@""];
                    
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"1-5"withString:@"01"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"6-10"withString:@"02"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"11-15"withString:@"03"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"16-20"withString:@"04"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"21-25"withString:@"05"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@"其他"withString:@"06"];
					sfcContent = [sfcContent stringByReplacingOccurrencesOfString:@" "withString:@""];
                    
					[content appendString:sfcContent];
				}
				if (ksArr.count > 0) {
					NSString *ksContent = [ksArr componentsJoinedByString:@"/"];
                    
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"客胜("withString:@""];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"主胜("withString:@""];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@")"withString:@""];
                    
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"1-5"withString:@"11"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"6-10"withString:@"12"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"11-15"withString:@"13"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"16-20"withString:@"14"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"21-25"withString:@"15"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@"其他"withString:@"16"];
					ksContent = [ksContent stringByReplacingOccurrencesOfString:@" "withString:@""];
					if (zsExist) {
						[content appendString:@"/"];
					}
					[content appendString:ksContent];
				}
				NSString *tag = @"^3_";
				if (bf) {
					tag = @"3_";
					bf = NO;
				}
				[teamhh appendString:[NSString stringWithFormat:@"%@%@", tag, content]];
			}
			//大小分
			if (dxfArr.count > 1) {
				NSString *tag = @"^4_";
				if (bf) {
					tag = @"4_";
					bf = NO;
				}
				NSMutableArray *dxfA = [NSMutableArray array];
				for (int i = 1; i < dxfArr.count; i++) {
					[dxfA addObject:[dxfArr objectAtIndex:i]];
				}
				NSString *dxfContent = [dxfA componentsJoinedByString:@"/"];
				dxfContent = [dxfContent stringByReplacingOccurrencesOfString:@"大分"withString:@"1"];
				dxfContent = [dxfContent stringByReplacingOccurrencesOfString:@"小分"withString:@"2"];
				dxfContent = [dxfContent stringByReplacingOccurrencesOfString:@" "withString:@""];
				[teamhh appendString:[NSString stringWithFormat:@"%@%@", tag, dxfContent]];
			}
		}
		//131101001=1
		//3 1 0 s p f
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
			[lotteryNumberString appendString:teamhh];
		}
		else {
			[lotteryNumberString appendString:team1];
		}
	}
	//最后增加|
	//131101001=3/1,131101002=3/1/0|
	[lotteryNumberString appendString:@"|"];
	for (int i = 0; i < [playMethodTemp count]; i++) {
		NSString *playMethod = [playMethodTemp objectAtIndex:i];
		NSString *playMethod2 = [self getPlayMethodNameWithNameStr:playMethod];
		if (i > 0) {
			[lotteryNumberString appendString:@","];
		}
		[lotteryNumberString appendString:playMethod2];
	}
	[lotteryNumberString appendString:@"|0"];
	[numDic setObject:lotteryNumberString forKey:@"number"];
	[paramNumberArray addObject:numDic];
	return paramNumberArray;
}

- (NSString *)getPlayMethodNameWithNameStr:(NSString *)name {
	NSString *playMethod2;
	if ([name isEqualToString:@"单关"]) {
		playMethod2 = @"1*1";
	}
	else if ([name isEqualToString:@"2串1"]) {
		playMethod2 = @"2*1";
	}
	else if ([name isEqualToString:@"3串1"]) {
		playMethod2 = @"3*1";
	}
	else if ([name isEqualToString:@"4串1"]) {
		playMethod2 = @"4*1";
	}
	else if ([name isEqualToString:@"5串1"]) {
		playMethod2 = @"5*1";
	}
	else if ([name isEqualToString:@"6串1"]) {
		playMethod2 = @"6*1";
	}
	else if ([name isEqualToString:@"7串1"]) {
		playMethod2 = @"7*1";
	}
	else if ([name isEqualToString:@"8串1"]) {
		playMethod2 = @"8*1";
	}
	return playMethod2;
}

- (void)BuyLotteryOperationResult:(NSData *)result {
	[JddCommonFunction setWaitingViewHidden:YES fromController:self];
    if (result) {
        NSDictionary *ReDic = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:nil];
        if([[ReDic objectForKey:@"Code"] intValue] == 0)
        {
            // modify by rainy  修改投注使用接口不经过web
            NSString * fanganhao = [ReDic objectForKey:@"Data"];
            alert1 = [JddAlertView getInstanceView];
            alert1.lssueString = fanganhao;
            alert1.moneylable = moneyLabel.text;
            [alert1 alertBuyMessage:@"竞彩篮球"];
//            NSString*checkUrlString = [NSString stringWithFormat:@"%@?ck=%@",BASE_SERVER_IOS_BUY_LOTTERY_URL,[ReDic objectForKey:@"Data"]];
//            NSURL *checkUrl = [NSURL URLWithString:checkUrlString];
//            [[UIApplication sharedApplication] openURL:checkUrl];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"购彩失败"                                                  message:[ReDic objectForKey:@"Data"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil,nil ];
            [alert show];
        }
//        [JddCommonFunction updateBuyLotteryListWithLotteryId:LOTTERY_TYPE_ID_BASKETBALL];
    }
}

- (void)selectMatch:(NSMutableArray *)reslutArray {
	playMethodTemp = [NSMutableArray arrayWithArray:reslutArray];
	NSMutableString *playMethodString = [NSMutableString string];
	for (NSString *playMethod1 in playMethodTemp) {
		[playMethodString appendString:playMethod1];
		[playMethodString appendString:@","];
	}
	passTypeLabel.text = playMethodString;
	[self caculateMoneyAndCount];
}

- (int)getNumWithSSqNumber:(JddSportNumber *)ssqNumber {
	NSMutableArray *resultArr = ssqNumber.teamArray;
	NSMutableArray *spfArr = [resultArr objectAtIndex:0];
	NSMutableArray *rqspfArr = [resultArr objectAtIndex:1];
	NSMutableArray *zjcArr = [resultArr objectAtIndex:2];
	NSMutableArray *bqcArr = [resultArr objectAtIndex:3];
	NSMutableArray *bfArr = [resultArr objectAtIndex:4];
	int num1 = 0;
	if (spfArr.count > 1) {
		for (int i = 1; i < spfArr.count; i++) {
			num1 += 1;
		}
	}
	if (rqspfArr.count > 1) {
		for (int i = 1; i < rqspfArr.count; i++) {
			num1 += 1;
		}
	}
	if (zjcArr.count > 1) {
		for (int i = 1; i < zjcArr.count; i++) {
			num1 += 1;
		}
	}
	if (bqcArr.count > 0) {
		for (int i = 0; i < bqcArr.count; i++) {
			num1 += 1;
		}
	}
	if (bfArr.count > 0) {
		for (int i = 0; i < bfArr.count; i++) {
			num1 += 1;
		}
	}
	return num1;
}

- (void)caculateMoneyAndCount {
	count = 0;
	for (NSString *platMethod in playMethodTemp) {
		if ([platMethod isEqualToString:@"单关"]) {
			for (int i = 0; i < [numberArray count]; ++i) {
				JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
				int num1 = [ssqNumber.teamArray count];
				count += num1;
			}
		}
		else if ([platMethod isEqualToString:@"2串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						count += num1 * num2;
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					//                    [self getTeamMaxSPWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						count += num1 * num2;
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"3串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							count += num1 * num2 * num3;
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							count += num1 * num2 * num3;
						}
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"4串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [self getNumWithSSqNumber:ssqNumber4];
								count += num1 * num2 * num3 * num4;
							}
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [ssqNumber4.teamArray count];
								count += num1 * num2 * num3 * num4;
							}
						}
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"5串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [self getNumWithSSqNumber:ssqNumber4];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [self getNumWithSSqNumber:ssqNumber5];
									count += num1 * num2 * num3 * num4 * num5;
								}
							}
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [ssqNumber4.teamArray count];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [ssqNumber5.teamArray count];
									count += num1 * num2 * num3 * num4 * num5;
								}
							}
						}
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"6串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [self getNumWithSSqNumber:ssqNumber4];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [self getNumWithSSqNumber:ssqNumber5];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [self getNumWithSSqNumber:ssqNumber6];
										count += num1 * num2 * num3 * num4 * num5 * num6;
									}
								}
							}
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [ssqNumber4.teamArray count];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [ssqNumber5.teamArray count];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [ssqNumber6.teamArray count];
										count += num1 * num2 * num3 * num4 * num5 * num6;
									}
								}
							}
						}
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"7串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [self getNumWithSSqNumber:ssqNumber4];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [self getNumWithSSqNumber:ssqNumber5];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [self getNumWithSSqNumber:ssqNumber6];
										for (int dan5 = dan4 + 1; dan5 < [numberArray count]; ++dan5) {
											JddSportNumber *ssqNumber7 = [numberArray objectAtIndex:dan5];
											int num7 = [self getNumWithSSqNumber:ssqNumber7];
											count += num1 * num2 * num3 * num4 * num5 * num6 * num7;
										}
									}
								}
							}
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [ssqNumber4.teamArray count];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [ssqNumber5.teamArray count];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [ssqNumber6.teamArray count];
										for (int dan5 = dan4 + 1; dan5 < [numberArray count]; ++dan5) {
											JddSportNumber *ssqNumber7 = [numberArray objectAtIndex:dan5];
											int num7 = [ssqNumber7.teamArray count];
											count += num1 * num2 * num3 * num4 * num5 * num6 * num7;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		else if ([platMethod isEqualToString:@"8串1"]) {
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [self getNumWithSSqNumber:ssqNumber];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [self getNumWithSSqNumber:ssqNumber2];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [self getNumWithSSqNumber:ssqNumber3];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [self getNumWithSSqNumber:ssqNumber4];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [self getNumWithSSqNumber:ssqNumber5];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [self getNumWithSSqNumber:ssqNumber6];
										for (int dan5 = dan4 + 1; dan5 < [numberArray count]; ++dan5) {
											JddSportNumber *ssqNumber7 = [numberArray objectAtIndex:dan5];
											int num7 = [self getNumWithSSqNumber:ssqNumber7];
											for (int dan6 = dan5 + 1; dan6 < [numberArray count]; ++dan6) {
												JddSportNumber *ssqNumber8 = [numberArray objectAtIndex:dan6];
												int num8 = [self getNumWithSSqNumber:ssqNumber8];
												count += num1 * num2 * num3 * num4 * num5 * num6 * num7 * num8;
											}
										}
									}
								}
							}
						}
					}
				}
			}
			else {
				for (int i = 0; i < [numberArray count]; ++i) {
					JddSportNumber *ssqNumber = [numberArray objectAtIndex:i];
					int num1 = [ssqNumber.teamArray count];
					for (int j = i + 1; j < [numberArray count]; ++j) {
						JddSportNumber *ssqNumber2 = [numberArray objectAtIndex:j];
						int num2 = [ssqNumber2.teamArray count];
						for (int dan1 = j + 1; dan1 < [numberArray count]; ++dan1) {
							JddSportNumber *ssqNumber3 = [numberArray objectAtIndex:dan1];
							int num3 = [ssqNumber3.teamArray count];
							for (int dan2 = dan1 + 1; dan2 < [numberArray count]; ++dan2) {
								JddSportNumber *ssqNumber4 = [numberArray objectAtIndex:dan2];
								int num4 = [ssqNumber4.teamArray count];
								for (int dan3 = dan2 + 1; dan3 < [numberArray count]; ++dan3) {
									JddSportNumber *ssqNumber5 = [numberArray objectAtIndex:dan3];
									int num5 = [ssqNumber5.teamArray count];
									for (int dan4 = dan3 + 1; dan4 < [numberArray count]; ++dan4) {
										JddSportNumber *ssqNumber6 = [numberArray objectAtIndex:dan4];
										int num6 = [ssqNumber6.teamArray count];
										for (int dan5 = dan4 + 1; dan5 < [numberArray count]; ++dan5) {
											JddSportNumber *ssqNumber7 = [numberArray objectAtIndex:dan5];
											int num7 = [ssqNumber7.teamArray count];
											for (int dan6 = dan5 + 1; dan6 < [numberArray count]; ++dan6) {
												JddSportNumber *ssqNumber8 = [numberArray objectAtIndex:dan6];
												int num8 = [ssqNumber8.teamArray count];
												count += num1 * num2 * num3 * num4 * num5 * num6 * num7 * num8;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	countLabel.text = [NSString stringWithFormat:@"%3.0f注", count];
	mutiLabel.text = [NSString stringWithFormat:@"%@倍", mutiTextField.text];
	moneyLabel.text = [NSString stringWithFormat:@"%3.0f彩豆", count * 2 *[mutiTextField.text floatValue]];
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
    [MobClick beginLogPageView:@"JCLQ-detail"];

//	[self setBackBtnAction];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
	self.titleLabel.text = [NSString stringWithFormat:@"共选择%d场,截止时间:%@", [numberArray count], [dateFormatter stringFromDate:endTime]];
	
    
	
    
    [playMethodTemp removeAllObjects];
    
    if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
        //胜分差
        if ([numberArray count] > 4) {
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",4];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",4]];
        }else{
            if([numberArray count] == 1){
                passTypeLabel.text = @"单关";
                [playMethodTemp addObject:[NSString stringWithFormat:@"%@",@"单关"]];
            }else{
                passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",[numberArray count]];
                [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",[numberArray count]]];
            }
        }
    }else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_RFSF){
        //让分胜负
        
        if ([numberArray count] > 8) {
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",8];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",8]];
        }else{
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",[numberArray count]];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",[numberArray count]]];
        }
    }else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SF){
        //胜负
        if ([numberArray count] > 8) {
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",8];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",8]];
        }else{
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",[numberArray count]];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",[numberArray count]]];
        }
    }else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_DXF){
        //大小分
        
        if ([numberArray count] > 8) {
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",8];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",8]];
        }else{
            passTypeLabel.text = [NSString stringWithFormat:@"%d串1,",[numberArray count]];
            [playMethodTemp addObject:[NSString stringWithFormat:@"%d串1",[numberArray count]]];
        }
    }else if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH){
        //混合
        
    }
    
    
    [self caculateMoneyAndCount];
    [numberListTable reloadData];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [MobClick endLogPageView:@"JCLQ-detail"];

    if ([mutiTextField.text length]==0) {
        mutiTextField.text = @"1";
    }
    [mutiTextField resignFirstResponder];
}
- (void)viewDidLoad {
	[super viewDidLoad];
//    //self.navigationItem.hidesBackButton = YES;
    
//    UIImage *leftImage = [UIImage imageNamed:@"navbar_back.png"];
//    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [leftBtn setBackgroundImage:leftImage forState:UIControlStateNormal];
//    leftBtn.frame = CGRectMake(0, 0, 12, 19);
//    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
//    self.navigationItem.leftBarButtonItem = leftItem;
    
    agreeLotteryForFooterView = [JddAgreeLotteryForFooterView getInstanceView];
    agreeLotteryForFooterView.fromViewController = self;
    numberListTable.tableFooterView = agreeLotteryForFooterView;

//	[self.navigationItem setTitle:@"竞彩篮球选队列表"];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:@"竞彩篮球选队列表"];
        customLab.textAlignment = NSTextAlignmentCenter;

        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;

    playMethodTemp = [[NSMutableArray alloc] init];
	passTypeLabel.text = @"";
    [numberListTable setSeparatorColor:SeparatorLineColor];
    if (IOS7) {
        [numberListTable setSeparatorInset:UIEdgeInsetsZero];
    }

}

- (void)destoryView {
	playMethodTemp = [[NSMutableArray alloc] init];
	numberArray = [[NSMutableArray alloc] init];
	[mutiTextField resignFirstResponder];
	mutiTextField.text = @"1";
	passTypeLabel.text = @"";
}

- (IBAction)coBuyBtnClick:(id)sender {
    if([self checkValue]){
    [FaQiHeMaiViewController sharedInstance].bs = [mutiTextField.text intValue];
    [FaQiHeMaiViewController sharedInstance].lotID = LOTTERY_TYPE_ID_BASKETBALL;
    [FaQiHeMaiViewController sharedInstance].issueID = @"2016";
    [FaQiHeMaiViewController sharedInstance].issueName = @"2016";
    [FaQiHeMaiViewController sharedInstance].issueNameTitle = [NSString stringWithFormat:@"竞彩篮球合买"];
    [FaQiHeMaiViewController sharedInstance].allMoney = count * [mutiTextField.text floatValue] * 2;
    [FaQiHeMaiViewController sharedInstance].lotteryNumber = [self lotteryNumberList];
    [[JddViewControllerManager sharedInstance].navigationController pushViewController:[FaQiHeMaiViewController sharedInstance] animated:YES];
    }
}

- (void)viewDidUnload {
	[self setTitleLabel:nil];
	[self setPassTypeLabel:nil];
	[self setCountLabel:nil];
	[self setMutiLabel:nil];
	[self setMoneyLabel:nil];
	[self setBgScrollView:nil];
	[self setNumberListTable:nil];
	[self setMutiTextField:nil];
	[self setBuyButton:nil];
	[super viewDidUnload];
}

- (IBAction)passTypeBtn:(id)sender {
	NSArray *playMethod = [[NSArray alloc] init];
	if (([numberArray count] > 1) || ([numberArray count] > 0 && self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC)) {
		//胜分差
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
			playMethod = [[NSArray alloc] initWithObjects:@"单关", @"2串1", @"3串1", @"4串1", nil];
		}
		else {
			playMethod = [[NSArray alloc] initWithObjects:@"2串1", @"3串1", @"4串1", @"5串1", @"6串1", @"7串1", @"8串1", nil];
		}
		int length = numberArray.count;
		//最多只有8串1
		if (length > 7) {
			length = 8;
		}
		//混合
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_HH) {
			BOOL zjq, bqc, bf;
			for (JddSportNumber *ssqNumber in numberArray) {
				NSMutableArray *resultArr = ssqNumber.teamArray;
				NSMutableArray *zjcArr = [resultArr objectAtIndex:2];
				NSMutableArray *bqcArr = [resultArr objectAtIndex:3];
				NSMutableArray *bfArr = [resultArr objectAtIndex:4];
				if (length > 4) {
					length = 4;
				}
                
				if (zjcArr.count > 1) {
					zjq = YES;
				}
				if (bqcArr.count > 1) {
					bqc = YES;
				}
				if (bfArr.count > 1) {
					bf = YES;
				}
			}
			//如果是胜分差，最多只有4串1
			if (bqc || bf) {
				if (length > 3) {
					length = 4;
				}
			}
		}
		else {
			//如果是胜分差，最多只有4串1
			if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
				if (length > 3) {
					length = 4;
				}
			}
		}
		NSMutableArray *newPlayMethod = [[NSMutableArray alloc] init];
		if (!(self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC)) {
			length -= 1;
		}
		for (int i = 0; i < length; i++) {
			[newPlayMethod addObject:[playMethod objectAtIndex:i]];
		}
		playMethod = newPlayMethod;
        
		CGRect rect = [[UIScreen mainScreen] bounds];
		rect.origin.x = (rect.size.width - 251) / 2.0;
		rect.origin.y = (rect.size.height - 139) / 2.0;
		rect.size.width = 251.0;
		rect.size.height = 139.0;
		comboBoxView = [JddComboBoxView getInstanceView];
		[comboBoxView setFrame:rect];
		comboBoxView.dataArray = [NSArray arrayWithArray:playMethod];
		comboBoxView.tempArray = [NSArray arrayWithArray:playMethodTemp];
		comboBoxView.commitLabel.hidden = YES;
		comboBoxView.type = 0;
		comboBoxView.delegate = self;
		[comboBoxView show];
	}
	else {
		NSString *message = @"请至少选择两场比赛！";
		if (self.playId == LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
			message = @"请至少选择一场比赛！";
		}
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:message
		                                               delegate:self
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:nil];
		[alert show];
	}
}

- (IBAction)addBtn:(id)sender {
	NSInteger multiple = [mutiTextField.text intValue];
	if (multiple-- < 2) {
		return;
	}
	mutiTextField.text = [NSString stringWithFormat:@"%d", multiple];
	mutiLabel.text = [NSString stringWithFormat:@"%d倍", multiple];
	moneyLabel.text = [NSString stringWithFormat:@"%3.0f彩豆", count * multiple * 2];
}

- (IBAction)reduceBtn:(id)sender {
	NSInteger multiple = [mutiTextField.text intValue];
	if (multiple > 99998) {
		return;
	}
	mutiTextField.text = [NSString stringWithFormat:@"%d", ++multiple];
	mutiLabel.text = [NSString stringWithFormat:@"%d倍", multiple];
	moneyLabel.text = [NSString stringWithFormat:@"%3.0f彩豆", count * multiple * 2];
}

- (IBAction)clearBtn:(id)sender {
//	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球" message:@"确认清空列表？" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
//	[alert show];
    
    if (numberArray.count >0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"确认清空列表？" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        [alert show];
    }else{
        
    }

}

- (IBAction)buyBtn:(id)sender {
	int multiple = [mutiTextField.text intValue];
	if (![JddCommonFunction isLogin]) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:@"您还没有登录，请先登录"
		                                               delegate:self
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:@"取消", nil];
		[alert show];
	}
	else {
		if (!agreeLotteryForFooterView.checkBoxBtn.selected) {
            [JddCommonFunction messageBoxWithMessage:BUY_NOT_READ];
        }
        else if ([numberArray count] == 0) {
			[JddCommonFunction messageBoxWithMessage:@"购买内容为空，请先选择投注场次"];
		}
		else if ([numberArray count] == 1&& self.playId != LOTTERY_PLAY_METHOD_BASKETBALL_SFC) {
			[JddCommonFunction messageBoxWithMessage:@"请至少选择2场比赛"];
		}
		else if (multiple == 0) {
			[JddCommonFunction messageBoxWithMessage:MULTIPLE_Tip];
		}
		else {
			if ([playMethodTemp count] == 0) {
				[JddCommonFunction messageBoxWithMessage:@"请至少选择一种过关方式"];
			}
			else {
                [self sureToBuy];
                /*
				UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球"
				                                                message:@"确认购买？"
				                                               delegate:self
				                                      cancelButtonTitle:@"确定"
				                                      otherButtonTitles:@"取消", nil];
				[alert show];*/
			}
		}
	}
}

- (IBAction)editDidEndTextFiled:(id)sender {
	[mutiTextField resignFirstResponder];
}

- (BOOL)checkValue {
	if ([mutiTextField.text intValue] > 99999) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
		                                                message:@"倍数不能大于99999"
		                                               delegate:nil
		                                      cancelButtonTitle:@"确定"
		                                      otherButtonTitles:nil, nil];
		[alert show];
		mutiTextField.text =  @"99999";
		return NO;
    }else if ((count * [mutiTextField.text intValue] * 2) > 2000000 ){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
                                                        message:@"单个方案的总金额必须在2彩豆至2000000彩豆之间"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil,nil ];
        [alert show];
        return NO;
    }
	return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
	return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end
